from YK_liushuai.Page.Page import Page
from YK_liushuai.Base import Base
from selenium.webdriver.common.by import By
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver import ActionChains,Keys
class Page2(Page):
    # 点击首页
    shouye_loc=(By.LINK_TEXT,'首页')
    def shouye(self):
        self.click(self.shouye_loc)
    #  搜索并回车
    sousuo_loc=(By.CLASS_NAME,'search-input')
    def sousuo(self):
        self.send_keys(self.sousuo_loc,'电水壶')
        self.key_enter(self.sousuo_loc)
    #  点击商品
    shangp_loc=(By.XPATH,'//img[@src="/uploads/images/20250620/67e1bd127f10d17039e45464df4c460a.jpg"]')
    def shangp(self):
        self.click(self.shangp_loc)
    # 加入购物车
    jiaru_loc=(By.ID,'add-cart')
    def jiaru(self):
        self.click(self.jiaru_loc)
    # 查看购物车
    chakna_loc=(By.XPATH,'/html/body/div[3]/div[3]/div[2]/a')
    def chakna(self):
        self.click(self.chakna_loc)
#     点击商品
    dianji_loc=(By.XPATH,'//*[@id="cart-box"]/div[1]/table/tbody/tr[2]/td[1]/input')
    def dianji(self):
        self.click(self.dianji_loc)
#     点击结算按钮
    jiesaun_loc=(By.XPATH,'//a[starts-with(@class,"ask-btn")]')
    def jiesaun(self):
        self.click(self.jiesaun_loc)
#     选择收货人
    shouhuo_loc=(By.XPATH,'//input[contains(@id,"address-834")]')
    def shouhuo(self):
        self.click(self.shouhuo_loc)
    #     点击下一步
    xiayibu_loc = (By.ID, 'order-button')

    def xiayibu(self):
            self.click(self.xiayibu_loc)
    #     断言订单完成
    dy1_loc = (By.XPATH, '/html/body/div[4]/div[1]/a[2]')
    def dy1(self):
        return self.text(self.dy1_loc)



    def test_a3mall_gouwuche(self):
        self.test_a3mall_login()
        self.shouye()
        self.sousuo()
        self.shangp()
        self.jiaru()
        self.chakna()
        # 隐式等待
        self.implicitly_wait(10)
        self.dianji()
        self.jiesaun()
        self.shouhuo()
        self.xiayibu()
        self.dy1()
        print("断言1：订单完成：", self.dy1())
        # 强制等待
        time.sleep(5)



